// pages/mine/coupon/moreList/moreList.js
let api = require('../../../../api/index'),
    app = getApp(),
    globalData = app.globalData,
    utils = require('../../../../utils/util');

Page({

    /**
     * 页面的初始数据
     */
    data: {
        couponsList: [],
        active: 1,
        imageBaseUri: globalData.imageBaseUri
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.reload()
    },

    reload() {
        this.getMyCoupons()
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    switchTab(e) {
        let tab = e.currentTarget.dataset.tab;
        this.setData({
            active: tab
        })
        this.getMyCoupons()
    },

    // 获取我的优惠券
    async getMyCoupons() {
        wx.showLoading({
            title: '加载中',
        })
        try {
            let res = await api.coupon.getMyCoupons(this.data.active),
                data = res.data.ResData || [];
            console.log(res, '我的优惠券列表')
            this.setData({
                couponsList: data
            })

        } catch (e) {
            console.log(e, '获取我的优惠券列表失败')
        } finally {
            wx.hideLoading()
        }

    },


})